

package com.mt.repair.controller.repairManagement;

import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


import com.mt.repair.dto.repairManagement.RepairOrderStatusRecordEditDto;
import com.mt.repair.entity.repairManagement.RepairOrderStatusRecord;
import com.mt.repair.service.repairManagement.RepairOrderStatusRecordService;
import com.mt.repair.service.repairManagement.RepairOrderService;


@Api(tags = "维修单状态记录")
@RestController
@RequestMapping("/api/repair/repairManagement/RepairOrderStatusRecord")
@CrossOrigin(allowCredentials = "true")
public class RepairOrderStatusRecordController {
    private static Logger logger = LoggerFactory.getLogger(RepairOrderStatusRecordController.class);


    @Autowired
    private RepairOrderStatusRecordService repairOrderStatusRecordService;
    @Autowired
    private RepairOrderService repairOrderService;

    /**
     * 根据分页参数查询维修单状态记录集合
     *
     * @param pageDTO 分页条件
     */
    //@PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:view')")
    @ApiOperation("分页查询维修单状态记录")
    @ApiPageParam
    @PostMapping("/findRepairOrderStatusRecords")
    public PageResultDTO findRepairOrderStatusRecords(@RequestBody PageDTO pageDTO) {
        return this.repairOrderStatusRecordService.findRepairOrderStatusRecords(pageDTO);
    }

    /**
     * 根据ID查询指定的维修单状态记录
     *
     * @param repairOrderStatusRecordId Id
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:view')")
    @ApiOperation("根据id查询维修单状态记录")
    @ApiPageParam
    @PostMapping("/findRepairOrderStatusRecord")
    public RepairOrderStatusRecord findRepairOrderStatusRecord(@RequestParam Long repairOrderStatusRecordId) {
        return this.repairOrderStatusRecordService.findRepairOrderStatusRecord(repairOrderStatusRecordId);
    }

    /**
     * 根据ID查询指定的维修单状态记录(包含外键名称)
     *
     * @param repairOrderStatusRecordId Id
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:view')")
    @ApiOperation("根据ID查询指定的维修单状态记录(包含外键名称)")
    @PostMapping("/findRepairOrderStatusRecordForView")
    public RepairOrderStatusRecord findRepairOrderStatusRecordForView(@RequestParam Long repairOrderStatusRecordId) {
        return this.repairOrderStatusRecordService.findRepairOrderStatusRecordWithForeignName(repairOrderStatusRecordId);
    }

    /**
     * 根据ID查询指定的维修单状态记录(包含维修单状态记录和外键名称)
     *
     * @param repairOrderStatusRecordId Id
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:view')")
    @ApiOperation("根据ID查询指定的维修单状态记录(包含维修单状态记录和外键名称)")
    @PostMapping("/findRepairOrderStatusRecordForEdit")
    public RepairOrderStatusRecordEditDto findRepairOrderStatusRecordForEdit(@RequestParam Long repairOrderStatusRecordId) {
        RepairOrderStatusRecordEditDto repairOrderStatusRecordEditDto = new RepairOrderStatusRecordEditDto();
        repairOrderStatusRecordEditDto.setRepairOrderStatusRecord(this.repairOrderStatusRecordService.findRepairOrderStatusRecordWithForeignName(repairOrderStatusRecordId));

        this.prepareRepairOrderStatusRecordEditDto(repairOrderStatusRecordEditDto);

        return repairOrderStatusRecordEditDto;
    }

    /**
     * 根据ID查询指定的维修单状态记录(只提取ID 和 Name)
     *
     * @param repairOrderStatusRecordId Id
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:view')")
    @ApiOperation("根据ID查询指定的维修单状态记录(只提取ID 和 Name)")
    @PostMapping("/findRepairOrderStatusRecordsWithIdNameById")
    public RepairOrderStatusRecord findRepairOrderStatusRecordsWithIdNameById(@RequestParam Long repairOrderStatusRecordId) {
        return this.repairOrderStatusRecordService.findRepairOrderStatusRecordsWithIdNameById(repairOrderStatusRecordId);
    }

    /**
     * 根据名称查询维修单状态记录集合(只提取ID 和 Name)
     *
     * @param repairOrderStatusRecordName 名称
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:view')")
    @ApiOperation("根据名称查询维修单状态记录集合(只提取ID 和 Name)")
    @PostMapping("/findRepairOrderStatusRecordsWithIdNameByName")
    public List<RepairOrderStatusRecord> findRepairOrderStatusRecordsWithIdNameByName(@RequestParam String repairOrderStatusRecordName) {
        return this.repairOrderStatusRecordService.findRepairOrderStatusRecordsWithIdNameByName(repairOrderStatusRecordName);
    }


    /**
     * 创建新的维修单状态记录
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:add')")
    @ApiOperation("创建新的维修单状态记录")
    @PostMapping("/createRepairOrderStatusRecord")
    public RepairOrderStatusRecordEditDto createRepairOrderStatusRecord() {
        RepairOrderStatusRecordEditDto repairOrderStatusRecordEditDto = new RepairOrderStatusRecordEditDto();
        repairOrderStatusRecordEditDto.setRepairOrderStatusRecord(new RepairOrderStatusRecord());

        this.prepareRepairOrderStatusRecordEditDto(repairOrderStatusRecordEditDto);
        return repairOrderStatusRecordEditDto;
    }

    private void prepareRepairOrderStatusRecordEditDto(RepairOrderStatusRecordEditDto repairOrderStatusRecordEditDto) {
        //TODO: 以下代码可以注释掉，此行代码即时加载所有外键对象，以便选择。如果不在此加载，可以在界面上实现延迟加载。如果外键对象超过 500 行，建议采用延迟加载
        repairOrderStatusRecordEditDto.setRepairOrderRepairOrders(this.repairOrderService.findAllRepairOrdersWithIdName());
    }

    /**
     * 新增保存维修单状态记录
     *
     * @param repairOrderStatusRecord 实体对象
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:add')")
    @ApiOperation("新增保存维修单状态记录")
    @PostMapping("/saveRepairOrderStatusRecord")
    public RepairOrderStatusRecord saveRepairOrderStatusRecord(@RequestBody RepairOrderStatusRecord repairOrderStatusRecord) {
        return this.repairOrderStatusRecordService.saveRepairOrderStatusRecord(repairOrderStatusRecord);
    }

    /**
     * 修改保存维修单状态记录
     *
     * @param repairOrderStatusRecord 实体对象
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:update')")
    @ApiOperation("修改保存维修单状态记录")
    @PostMapping("/updateRepairOrderStatusRecord")
    public RepairOrderStatusRecord updateRepairOrderStatusRecord(@RequestBody RepairOrderStatusRecord repairOrderStatusRecord) {
        return this.repairOrderStatusRecordService.updateRepairOrderStatusRecord(repairOrderStatusRecord);
    }

    /**
     * 根据ID删除维修单状态记录
     *
     * @param repairOrderStatusRecordId ID
     */
    @PreAuthorize("hasAuthority('repair:repairManagement:RepairOrderStatusRecord:remove')")
    @ApiOperation("根据ID删除维修单状态记录")
    @PostMapping("/deleteRepairOrderStatusRecord")
    public void deleteRepairOrderStatusRecord(@RequestParam Long repairOrderStatusRecordId) {
        this.repairOrderStatusRecordService.deleteRepairOrderStatusRecord(repairOrderStatusRecordId);
    }


}

